package command;

import java.net.InetAddress;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import base.*;
import utilities.*;

public class LookCommand extends Command{
	
	InetAddress ip;
	private int port;
	
	private List<Criterion> criterions;
	private String sresponse;
	
	public LookCommand(){
		this.criterions = new LinkedList<Criterion>();
	}

	public void addCriterion(Criterion c){
		this.criterions.add(c);
	}
	
	public boolean run(){
		DataTracker d = new DataTracker();
		d.createEm();
		String request = "";
		for(Criterion c: criterions){   	          		
			switch (c.getParam()){
			case FILENAME:
				request = d.findFileByName(request, c.getValue());
			break;
			case FILESIZE:
				request = d.findFileByLength(request, Integer.parseInt(c.getValue()), c.getOperator());
			default:
			}
		}
		List<File> result = d.executeFile(request);
		this.sresponse = d.responseLook(result);
		return true;
	}
	
	
	/**
	    * Sets the ip for this instance.
	    *
	    * @param ip The ip.
	    */
	   public void setIp(InetAddress ip)
	   {
	      this.ip = ip;
	   }

	   /**
	    * Sets the port for this instance.
	    *
	    * @param port The port.
	    */
	   public void setPort(int port)
	   {
	      this.port = port;
	   }


	   public String getSresponse() 
	   {
		   return sresponse;
	   }

	
	
	
	
	
	

}
